package com.zabra.zl.ui.detailsallocatin.presenter;

import com.zabra.zl.App;
import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.SimpleBean;
import com.zabra.zl.ui.detailsallocatin.contract.DetailsAllocationContract;
import com.zabra.zl.ui.detailsallocatin.model.DetailsAllocationModel;
import com.zabra.zl.utils.SharedPreferencesUtil;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class DetailsAllocationPresenter extends BasePresenter<DetailsAllocationContract.View> implements DetailsAllocationContract.Presenter {
    private DetailsAllocationContract.Model model;
    public DetailsAllocationPresenter() {
        model=new DetailsAllocationModel();
    }

    @Override
    public void getAddCashData(int bpOrderId, String money) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getAddCashData(bpOrderId, money).enqueue(new Callback<SimpleBean>() {
            @Override
            public void onResponse(Call<SimpleBean> call, Response<SimpleBean> response) {
                mView.hideLoading();
                mView.onSuccessAddCash(response.body());
                SharedPreferencesUtil.getInstance(App.context).putSP("token",response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<SimpleBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });
    }

    @Override
    public void getOverDealData(int bpOrderId) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getOverDealData(bpOrderId).enqueue(new Callback<SimpleBean>() {
            @Override
            public void onResponse(Call<SimpleBean> call, Response<SimpleBean> response) {
                mView.hideLoading();
                mView.onSuccessOver(response.body());
                SharedPreferencesUtil.getInstance(App.context).putSP("token",response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<SimpleBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });
    }
}
